﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TmU220PrintHelperV2d0.Entity;
using TmU220PrintHelperV2d0.Service;

namespace TmU220PrintHelperV2d0.Singleton
{
    /// <summary>
    /// 系统配置信息单例
    /// </summary>
    public class SysCfgInfoSingletonV1d0
    {
        private static SysCfgInfoSingletonV1d0 _instance = null;
        private static SysCfgInfoV1d0 sysCfgInfo = null;
        private static readonly object syslock = new object();
        /// <summary>
        /// 单例模式
        /// </summary>
        public static SysCfgInfoSingletonV1d0 Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (syslock)
                    {
                        if (_instance == null)
                        {
                            _instance = new SysCfgInfoSingletonV1d0();
                        }
                    }
                }
                return _instance;
            }
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        private SysCfgInfoSingletonV1d0()
        {
            LoadData();
        }
        /// <summary>
        /// 装载数据
        /// </summary>
        private void LoadData()
        {
            string currDir = System.IO.Directory.GetCurrentDirectory();
            string filename = currDir + @"\parameter\sysCfgInfo.xml";
            if (File.Exists(filename))
            {
                sysCfgInfo = HotchPotchV2d0.ReadFromXmlFile<SysCfgInfoV1d0>(filename);
            }
            else
            {
                sysCfgInfo = new SysCfgInfoV1d0();
                HotchPotchV2d0.SaveToXmFile<SysCfgInfoV1d0>(sysCfgInfo, filename);
            }
        }
        /// <summary>
        /// 得到默认的系统配置信息文件名
        /// </summary>
        /// <returns></returns>
        public string GetSysCfgInfoFilename()
        {
            string currDir = System.IO.Directory.GetCurrentDirectory();
            string filename = currDir + @"\parameters\sysCfgInfo.xml";
            return filename;
        }
        public SysCfgInfoV1d0 GetSysCfgInfo()
        {
            return sysCfgInfo;
        }
        public int GetTimeoutOfTask()
        {
            return sysCfgInfo.TimeoutOfTask;
        }
        public int GetIntervalOfCheckTask()
        {
            return sysCfgInfo.IntervalOfCheckTask;
        }
        public string GetApiMainUrl()
        {
            return sysCfgInfo.ApiMainUrl;
        }
        public int GetShopId()
        {
            return sysCfgInfo.ShopId;
        }
        public bool GetIsGetPrinterCfgFromMemote()
        {
            return sysCfgInfo.IsGetPrinterCfgFromRemote;
        }
    }
}
